﻿using System;
using System.Drawing;
using OnOne.Lib;

/***** ESTA CLASSE EXTENDE OS TIPOS PRIMITIVOS E DERIVAROS ASSIM COMO TIPOS PRE-DEFINIDOS *****/

public static class clsExtensions
{
  private static Functions Funcoes = new Functions();

  #region Strings

  public static string ToMD5(this string value, String sPar = "")
  {
    System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();

    byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(value);
    byte[] hash = md5.ComputeHash(inputBytes);

    System.Text.StringBuilder sb = new System.Text.StringBuilder();

    for (int i = 0; i < hash.Length; i++)
    {
      sb.Append(hash[i].ToString("X2"));
    }

    return sb.ToString();
  }

  public static bool IsNull(this string value)
  {
    return (value == null);
  }

  public static string NullToEmpty(this string value)
  {
    if (value == null)
      return "";
    else
      return value;
  }

  public static string Quotes(this string value)
  {
    return Funcoes.Quotes(value);
  }

  public static string IIF(this string value, Boolean bEval, String sValueTrue, String sValueFalse)
  {
    return Funcoes.IIF(bEval, sValueTrue, sValueFalse);
  }

  public static string Choose(this string value, int index, String[] avalues)
  {
    return Funcoes.Choose(index, avalues);
  }

  public static string FmtDateForDB(this string value)
  {
    value = Funcoes.FmtDateDB(Convert.ToDateTime(value));
    return value;
  }

  public static float ToFloat(this string value)
  {
    return System.Convert.ToSingle(value);
  }

  public static int Length(this string value)
  {
    return value.Trim().Length;
  }

  public static float Value(this string value)
  {
    return value.ToFloat();
  }

  #endregion

  #region Valores Numeros

  public static string FmtMoney(this float value)
  {
    return Funcoes.FmtMoney(value);
  }

  public static string FmtMoneyDB(this float value)
  {
    return Funcoes.FmtMoneyDB(value);
  }

  #endregion

  #region Pictures

  public static Image Clear(this Image value)
  {
    return null;
  }

  #endregion
}